home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / BHO / pSimpleBHO_TLB.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-06-17  |  13.9 KB  |  434 lines

  1. unit pSimpleBHO_TLB;
  2.  
  3. // ************************************************************************ //
  4. // WARNING                                                                    
  5. // -------                                                                    
  6. // The types declared in this file were generated from data read from a       
  7. // Type Library. If this type library is explicitly or indirectly (via        
  8. // another type library referring to this type library) re-imported, or the   
  9. // 'Refresh' command of the Type Library Editor activated while editing the   
  10. // Type Library, the contents of this file will be regenerated and all        
  11. // manual modifications will be lost.                                         
  12. // ************************************************************************ //
  13.  
  14. // PASTLWTR : $Revision:   1.88  $
  15. // File generated on 7/7/00 11:34:11 AM from Type Library described below.
  16.  
  17. // *************************************************************************//
  18. // NOTE:                                                                      
  19. // Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
  20. // which return objects that may need to be explicitly created via a function 
  21. // call prior to any access via the property. These items have been disabled  
  22. // in order to prevent accidental use from within the object inspector. You   
  23. // may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
  24. // removing them from the $IFDEF blocks. However, such items must still be    
  25. // programmatically created via a method of the appropriate CoClass before    
  26. // they can be used.                                                          
  27. // ************************************************************************ //
  28. // Type Lib: F:\Program Files\Borland\Delphi5\Projects\BHO\pSimpleBHO.tlb (1)
  29. // IID\LCID: {5476D9C0-444E-11D4-ACEF-080000178968}\0
  30. // Helpfile: 
  31. // DepndLst: 
  32. //   (1) v2.0 stdole, (E:\WINNT\System32\StdOle2.Tlb)
  33. //   (2) v4.0 StdVCL, (E:\WINNT\System32\STDVCL40.DLL)
  34. // ************************************************************************ //
  35. {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
  36. interface
  37.  
  38. uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
  39.  
  40. // *********************************************************************//
  41. // GUIDS declared in the TypeLibrary. Following prefixes are used:        
  42. //   Type Libraries     : LIBID_xxxx                                      
  43. //   CoClasses          : CLASS_xxxx                                      
  44. //   DISPInterfaces     : DIID_xxxx                                       
  45. //   Non-DISP interfaces: IID_xxxx                                        
  46. // *********************************************************************//
  47. const
  48.   // TypeLibrary Major and minor versions
  49.   pSimpleBHOMajorVersion = 1;
  50.   pSimpleBHOMinorVersion = 0;
  51.  
  52.   LIBID_pSimpleBHO: TGUID = '{5476D9C0-444E-11D4-ACEF-080000178968}';
  53.  
  54.   IID_IMyBHO: TGUID = '{5476D9C1-444E-11D4-ACEF-080000178968}';
  55.   CLASS_MyBHO: TGUID = '{5476D9C3-444E-11D4-ACEF-080000178968}';
  56.   IID_IInfoBHO: TGUID = '{5476D9CA-444E-11D4-ACEF-080000178968}';
  57.   CLASS_InfoBHO: TGUID = '{5476D9CC-444E-11D4-ACEF-080000178968}';
  58. type
  59.  
  60. // *********************************************************************//
  61. // Forward declaration of types defined in TypeLibrary                    
  62. // *********************************************************************//
  63.   IMyBHO = interface;
  64.   IInfoBHO = interface;
  65.   IInfoBHODisp = dispinterface;
  66.  
  67. // *********************************************************************//
  68. // Declaration of CoClasses defined in Type Library                       
  69. // (NOTE: Here we map each CoClass to its Default Interface)              
  70. // *********************************************************************//
  71.   MyBHO = IMyBHO;
  72.   InfoBHO = IInfoBHO;
  73.  
  74.  
  75. // *********************************************************************//
  76. // Interface: IMyBHO
  77. // Flags:     (256) OleAutomation
  78. // GUID:      {5476D9C1-444E-11D4-ACEF-080000178968}
  79. // *********************************************************************//
  80.   IMyBHO = interface(IUnknown)
  81.     ['{5476D9C1-444E-11D4-ACEF-080000178968}']
  82.   end;
  83.  
  84. // *********************************************************************//
  85. // Interface: IInfoBHO
  86. // Flags:     (4416) Dual OleAutomation Dispatchable
  87. // GUID:      {5476D9CA-444E-11D4-ACEF-080000178968}
  88. // *********************************************************************//
  89.   IInfoBHO = interface(IDispatch)
  90.     ['{5476D9CA-444E-11D4-ACEF-080000178968}']
  91.   end;
  92.  
  93. // *********************************************************************//
  94. // DispIntf:  IInfoBHODisp
  95. // Flags:     (4416) Dual OleAutomation Dispatchable
  96. // GUID:      {5476D9CA-444E-11D4-ACEF-080000178968}
  97. // *********************************************************************//
  98.   IInfoBHODisp = dispinterface
  99.     ['{5476D9CA-444E-11D4-ACEF-080000178968}']
  100.   end;
  101.  
  102. // *********************************************************************//
  103. // The Class CoMyBHO provides a Create and CreateRemote method to          
  104. // create instances of the default interface IMyBHO exposed by              
  105. // the CoClass MyBHO. The functions are intended to be used by             
  106. // clients wishing to automate the CoClass objects exposed by the         
  107. // server of this typelibrary.                                            
  108. // *********************************************************************//
  109.   CoMyBHO = class
  110.     class function Create: IMyBHO;
  111.     class function CreateRemote(const MachineName: string): IMyBHO;
  112.   end;
  113.  
  114.  
  115. // *********************************************************************//
  116. // OLE Server Proxy class declaration
  117. // Server Object    : TMyBHO
  118. // Help String      : MyBHO Object
  119. // Default Interface: IMyBHO
  120. // Def. Intf. DISP? : No
  121. // Event   Interface: 
  122. // TypeFlags        : (2) CanCreate
  123. // *********************************************************************//
  124. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  125.   TMyBHOProperties= class;
  126. {$ENDIF}
  127.   TMyBHO = class(TOleServer)
  128.   private
  129.     FIntf:        IMyBHO;
  130. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  131.     FProps:       TMyBHOProperties;
  132.     function      GetServerProperties: TMyBHOProperties;
  133. {$ENDIF}
  134.     function      GetDefaultInterface: IMyBHO;
  135.   protected
  136.     procedure InitServerData; override;
  137.   public
  138.     constructor Create(AOwner: TComponent); override;
  139.     destructor  Destroy; override;
  140.     procedure Connect; override;
  141.     procedure ConnectTo(svrIntf: IMyBHO);
  142.     procedure Disconnect; override;
  143.     property  DefaultInterface: IMyBHO read GetDefaultInterface;
  144.   published
  145. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  146.     property Server: TMyBHOProperties read GetServerProperties;
  147. {$ENDIF}
  148.   end;
  149.  
  150. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  151. // *********************************************************************//
  152. // OLE Server Properties Proxy Class
  153. // Server Object    : TMyBHO
  154. // (This object is used by the IDE's Property Inspector to allow editing
  155. //  of the properties of this server)
  156. // *********************************************************************//
  157.  TMyBHOProperties = class(TPersistent)
  158.   private
  159.     FServer:    TMyBHO;
  160.     function    GetDefaultInterface: IMyBHO;
  161.     constructor Create(AServer: TMyBHO);
  162.   protected
  163.   public
  164.     property DefaultInterface: IMyBHO read GetDefaultInterface;
  165.   published
  166.   end;
  167. {$ENDIF}
  168.  
  169.  
  170. // *********************************************************************//
  171. // The Class CoInfoBHO provides a Create and CreateRemote method to          
  172. // create instances of the default interface IInfoBHO exposed by              
  173. // the CoClass InfoBHO. The functions are intended to be used by             
  174. // clients wishing to automate the CoClass objects exposed by the         
  175. // server of this typelibrary.                                            
  176. // *********************************************************************//
  177.   CoInfoBHO = class
  178.     class function Create: IInfoBHO;
  179.     class function CreateRemote(const MachineName: string): IInfoBHO;
  180.   end;
  181.  
  182.  
  183. // *********************************************************************//
  184. // OLE Server Proxy class declaration
  185. // Server Object    : TInfoBHO
  186. // Help String      : InfoBHO Object
  187. // Default Interface: IInfoBHO
  188. // Def. Intf. DISP? : No
  189. // Event   Interface: 
  190. // TypeFlags        : (2) CanCreate
  191. // *********************************************************************//
  192. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  193.   TInfoBHOProperties= class;
  194. {$ENDIF}
  195.   TInfoBHO = class(TOleServer)
  196.   private
  197.     FIntf:        IInfoBHO;
  198. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  199.     FProps:       TInfoBHOProperties;
  200.     function      GetServerProperties: TInfoBHOProperties;
  201. {$ENDIF}
  202.     function      GetDefaultInterface: IInfoBHO;
  203.   protected
  204.     procedure InitServerData; override;
  205.   public
  206.     constructor Create(AOwner: TComponent); override;
  207.     destructor  Destroy; override;
  208.     procedure Connect; override;
  209.     procedure ConnectTo(svrIntf: IInfoBHO);
  210.     procedure Disconnect; override;
  211.     property  DefaultInterface: IInfoBHO read GetDefaultInterface;
  212.   published
  213. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  214.     property Server: TInfoBHOProperties read GetServerProperties;
  215. {$ENDIF}
  216.   end;
  217.  
  218. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  219. // *********************************************************************//
  220. // OLE Server Properties Proxy Class
  221. // Server Object    : TInfoBHO
  222. // (This object is used by the IDE's Property Inspector to allow editing
  223. //  of the properties of this server)
  224. // *********************************************************************//
  225.  TInfoBHOProperties = class(TPersistent)
  226.   private
  227.     FServer:    TInfoBHO;
  228.     function    GetDefaultInterface: IInfoBHO;
  229.     constructor Create(AServer: TInfoBHO);
  230.   protected
  231.   public
  232.     property DefaultInterface: IInfoBHO read GetDefaultInterface;
  233.   published
  234.   end;
  235. {$ENDIF}
  236.  
  237.  
  238. procedure Register;
  239.  
  240. implementation
  241.  
  242. uses ComObj;
  243.  
  244. class function CoMyBHO.Create: IMyBHO;
  245. begin
  246.   Result := CreateComObject(CLASS_MyBHO) as IMyBHO;
  247. end;
  248.  
  249. class function CoMyBHO.CreateRemote(const MachineName: string): IMyBHO;
  250. begin
  251.   Result := CreateRemoteComObject(MachineName, CLASS_MyBHO) as IMyBHO;
  252. end;
  253.  
  254. procedure TMyBHO.InitServerData;
  255. const
  256.   CServerData: TServerData = (
  257.     ClassID:   '{5476D9C3-444E-11D4-ACEF-080000178968}';
  258.     IntfIID:   '{5476D9C1-444E-11D4-ACEF-080000178968}';
  259.     EventIID:  '';
  260.     LicenseKey: nil;
  261.     Version: 500);
  262. begin
  263.   ServerData := @CServerData;
  264. end;
  265.  
  266. procedure TMyBHO.Connect;
  267. var
  268.   punk: IUnknown;
  269. begin
  270.   if FIntf = nil then
  271.   begin
  272.     punk := GetServer;
  273.     Fintf:= punk as IMyBHO;
  274.   end;
  275. end;
  276.  
  277. procedure TMyBHO.ConnectTo(svrIntf: IMyBHO);
  278. begin
  279.   Disconnect;
  280.   FIntf := svrIntf;
  281. end;
  282.  
  283. procedure TMyBHO.DisConnect;
  284. begin
  285.   if Fintf <> nil then
  286.   begin
  287.     FIntf := nil;
  288.   end;
  289. end;
  290.  
  291. function TMyBHO.GetDefaultInterface: IMyBHO;
  292. begin
  293.   if FIntf = nil then
  294.     Connect;
  295.   Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  296.   Result := FIntf;
  297. end;
  298.  
  299. constructor TMyBHO.Create(AOwner: TComponent);
  300. begin
  301.   inherited Create(AOwner);
  302. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  303.   FProps := TMyBHOProperties.Create(Self);
  304. {$ENDIF}
  305. end;
  306.  
  307. destructor TMyBHO.Destroy;
  308. begin
  309. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  310.   FProps.Free;
  311. {$ENDIF}
  312.   inherited Destroy;
  313. end;
  314.  
  315. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  316. function TMyBHO.GetServerProperties: TMyBHOProperties;
  317. begin
  318.   Result := FProps;
  319. end;
  320. {$ENDIF}
  321.  
  322. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  323. constructor TMyBHOProperties.Create(AServer: TMyBHO);
  324. begin
  325.   inherited Create;
  326.   FServer := AServer;
  327. end;
  328.  
  329. function TMyBHOProperties.GetDefaultInterface: IMyBHO;
  330. begin
  331.   Result := FServer.DefaultInterface;
  332. end;
  333.  
  334. {$ENDIF}
  335.  
  336. class function CoInfoBHO.Create: IInfoBHO;
  337. begin
  338.   Result := CreateComObject(CLASS_InfoBHO) as IInfoBHO;
  339. end;
  340.  
  341. class function CoInfoBHO.CreateRemote(const MachineName: string): IInfoBHO;
  342. begin
  343.   Result := CreateRemoteComObject(MachineName, CLASS_InfoBHO) as IInfoBHO;
  344. end;
  345.  
  346. procedure TInfoBHO.InitServerData;
  347. const
  348.   CServerData: TServerData = (
  349.     ClassID:   '{5476D9CC-444E-11D4-ACEF-080000178968}';
  350.     IntfIID:   '{5476D9CA-444E-11D4-ACEF-080000178968}';
  351.     EventIID:  '';
  352.     LicenseKey: nil;
  353.     Version: 500);
  354. begin
  355.   ServerData := @CServerData;
  356. end;
  357.  
  358. procedure TInfoBHO.Connect;
  359. var
  360.   punk: IUnknown;
  361. begin
  362.   if FIntf = nil then
  363.   begin
  364.     punk := GetServer;
  365.     Fintf:= punk as IInfoBHO;
  366.   end;
  367. end;
  368.  
  369. procedure TInfoBHO.ConnectTo(svrIntf: IInfoBHO);
  370. begin
  371.   Disconnect;
  372.   FIntf := svrIntf;
  373. end;
  374.  
  375. procedure TInfoBHO.DisConnect;
  376. begin
  377.   if Fintf <> nil then
  378.   begin
  379.     FIntf := nil;
  380.   end;
  381. end;
  382.  
  383. function TInfoBHO.GetDefaultInterface: IInfoBHO;
  384. begin
  385.   if FIntf = nil then
  386.     Connect;
  387.   Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  388.   Result := FIntf;
  389. end;
  390.  
  391. constructor TInfoBHO.Create(AOwner: TComponent);
  392. begin
  393.   inherited Create(AOwner);
  394. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  395.   FProps := TInfoBHOProperties.Create(Self);
  396. {$ENDIF}
  397. end;
  398.  
  399. destructor TInfoBHO.Destroy;
  400. begin
  401. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  402.   FProps.Free;
  403. {$ENDIF}
  404.   inherited Destroy;
  405. end;
  406.  
  407. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  408. function TInfoBHO.GetServerProperties: TInfoBHOProperties;
  409. begin
  410.   Result := FProps;
  411. end;
  412. {$ENDIF}
  413.  
  414. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  415. constructor TInfoBHOProperties.Create(AServer: TInfoBHO);
  416. begin
  417.   inherited Create;
  418.   FServer := AServer;
  419. end;
  420.  
  421. function TInfoBHOProperties.GetDefaultInterface: IInfoBHO;
  422. begin
  423.   Result := FServer.DefaultInterface;
  424. end;
  425.  
  426. {$ENDIF}
  427.  
  428. procedure Register;
  429. begin
  430.   RegisterComponents('Servers',[TMyBHO, TInfoBHO]);
  431. end;
  432.  
  433. end.
  434.